import { defineConfig } from 'vite'
import path from 'path'
import vue from '@vitejs/plugin-vue'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import tailwindcss from 'tailwindcss'
import autoprefixer from 'autoprefixer'
import { viteMockServe } from 'vite-plugin-mock'

const resolve = (dir: string) => path.resolve(__dirname, '.', dir)



// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    viteMockServe({
      mockPath: "src/mock",
      // localEnabled: process.env.NODE_ENV !== "production", // true 的时候会请求本地
      // localEnabled: command === "serve", // 开发时应用，// true 的时候会请求 mock
      logger: true
    }),
    AutoImport({
      resolvers: [ElementPlusResolver()],
    }),
    Components({
      resolvers: [ElementPlusResolver()],
    })
  ],
  resolve: {
    // 配置路径别名
    alias: {
      '@': resolve('src'),
      'components': resolve('src/components')
    },
    // 省略文件后缀
    extensions: ['', '.js', '.json', '.vue', '.scss', '.css', '.ts', '.tsx']
  },
  css: {
    postcss: {
      plugins: [tailwindcss, autoprefixer],
    },
  },
})
